home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / usr / bin / gnome-power-cmd < prev    next >
Encoding:
Text File  |  2009-04-08  |  1.4 KB  |  46 lines

  1. #!/bin/sh
  2. # Copyright (C) 2007 Richard Hughes <richard@hughsie.com>
  3. #
  4. # Licensed under the GNU General Public License Version 2
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation; either version 2 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # This program is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. # GNU General Public License for more details.
  15.  
  16. #$1 = method name
  17. execute_dbus_method ()
  18. {
  19.     dbus-send --session --dest=org.freedesktop.PowerManagement        \
  20.           --type=method_call --print-reply --reply-timeout=2000    \
  21.           /org/freedesktop/PowerManagement             \
  22.           org.freedesktop.PowerManagement.$1
  23.     if [ $? -ne 0 ]; then
  24.         echo "Failed"
  25.     fi 
  26. }
  27.  
  28. if [ "$1" = "suspend" ]; then
  29.     echo "Suspending"
  30.     execute_dbus_method "Suspend"
  31. elif [ "$1" = "hibernate" ]; then
  32.     echo "Hibernating"
  33.     execute_dbus_method "Hibernate"
  34. elif [ "$1" = "reboot" ]; then
  35.     echo "Rebooting"
  36.     execute_dbus_method "Reboot"
  37. elif [ "$1" = "shutdown" ]; then
  38.     echo "Shutting down"
  39.     execute_dbus_method "Shutdown"
  40. elif [ "$1" = "" ]; then
  41.     echo "command required: suspend, shutdown, hibernate or reboot"
  42. else
  43.     echo "command '$1' not recognised, only suspend, shutdown, hibernate or reboot are valid"
  44.     exit 1
  45. fi
  46.